package com.itheima.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheim.client.pojo.Address;
import com.itheim.client.vo.AddressVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author longbosheng
 * @Date 2022/6/21 9:23
 * @PackageName:com.itheima.mapper
 * @ClassName: AddressMapper
 * @Description: TODO
 * @Version 1.0
 */
@Mapper
public interface AddressMapper extends BaseMapper<Address> {
    /**
     * 获取该用户全部的地址
     * @param id
     * @return
     */
    @Select("select * from address where user_id = #{id}")
    List<AddressVo> addressList(String id);

    /**
     * 按照地址id查询信息
     * @param id
     * @return
     */
    @Select("select * from address where id = #{id}")
    AddressVo AddressInfo(String id);

    /**
     * 获取该用户的默认地址
     * @param id
     * @return
     */
    @Select("select * from address where is_default = 1 and user_id = #{id}")
    AddressVo getDefaultAddress(String id);

    /**
     * 将该地址更改为默认地址
     * @param address
     * @return
     */
    @Update("update address set is_default = #{isDefault} where id=#{id}")
    int setDefaultAddress(Address address);

    @Select("select * from address where is_default = 1 and user_id = #{id}")
    Address getDefault(String id);
}
